/**
 * Created by 追风少年 on 2018/6/12.
 */
var tableObj;
var table;

var closeWinAndFlush = function(){
    layer.closeAll('iframe'); //关闭所有的iframe层
    doQuery(1);
};

layui.use('table', function () {
    table = layui.table;
    tableObj = table.render({
        elem: '#datas',
        url: '/admin/serviceModel/findPage',
        height: 'full-220', //设置高度
        width: $("body").width() - 35,
        id: "datas",
        method: 'post',
        cols: [[ //标题栏
            {checkbox: true},
            {field: 'id', title: '服务编号', width: 220, sort: true},
            {field: 'service_name', title: '服务名称', width: 150, sort: false},
            {field: 'rolename', title: '执行部门', width: 300, sort: false},
            {field: 'inputdate', title: '添加时间', width: 220, sort: false},
            {field: 'updatedate', title: '更新时间', width: 220, sort: false}
        ]],
        page: true,
        limits: [10, 20, 30, 50, 100],
        limit: 10
        //支持所有基础参数
    });
    $("#doQuery").click(function () {
        doQuery(1);
    });

    $("#add").click(function () {
        Utils.openInputWin("新增服务",'/admin/serviceModel/inputPage');
    });

    $("#edit").click(function () {
        var checkStatus = table.checkStatus('datas'); //test即为基础参数id对应的值
        var rows = checkStatus.data;
        if(rows.length != 1){
            layer.msg(COMMON.MSG.EDIT_MSG);
            return false;
        }
        Utils.openInputWin("修改服务",'/admin/serviceModel/inputPage?id='+rows[0].id);
    });

    // $("#info").click(function () {
    //     var checkStatus = table.checkStatus('datas'); //test即为基础参数id对应的值
    //     var rows = checkStatus.data;
    //     if(rows.length != 1){
    //         layer.msg(COMMON.MSG.INFO_MSG);
    //         return false;
    //     }
    //     Utils.openInfoWin("服务详情",'/admin/serviceModel/infoPage?id='+rows[0].id);
    // });

});
function doQuery(pagenum) {
    tableObj.reload({ //其它参数在此省略
        id: 'datas',
        method: 'post',
        pagenum: pagenum,
        url: '/admin/serviceModel/findPage?' + decodeURIComponent(decodeURI($('#form').serialize()), true)
    });
}